#  路径总和
# Definition for a binary tree node.
class TreeNode:
    def __init__(self, x):
        self.val = x
        self.left = None
        self.right = None


class Solution:
    def hasPathSum(self, root: TreeNode, sum: int) -> bool:
        if root is None:
            return False
        if root.left is None and root.right is None:
            if sum == root.val:
                return True
            else:
                return False
        left = False
        if root.left is not None:
            left = self.hasPathSum(root.left, sum - root.val)
        if left:
            return True
        if root.right is not None:
            return self.hasPathSum(root.right, sum - root.val)
        return False


if __name__ == '__main__':
    so = Solution()
    root = TreeNode(1)
    root.left = TreeNode(0)
    root.left.right = TreeNode(-5)
    root.right = TreeNode(10)
    r = so.hasPathSum(root , 1)
    print(r)
